import requests

from lxml import etree

url = 'https://www.gushiwen.cn/mingjus/'
res = requests.get(url)
# print(res.text)
tree = etree.HTML(res.text)
titles = tree.xpath('//div[@id ="type2"]/div[@class = "sright"]/a/text()')

for title in titles:
    page = 1
    while True:
        link =f'https://www.gushiwen.cn/mingjus/default.aspx?page={page}&astr={title}'
        # print(link)
        print("22222222222222")

        res_link = requests.get(link)
        tree = etree.HTML(res_link.text)
        tree1 = etree.HTML(res_link.text)
        items = tree1.xpath('// div[ @class ="left"] / div[@ class = "sons"] / div[@ class ="cont"]')
        for item in items:
            print(item.xpath('./a[1]/text()')[0],)


        is_page = tree1.xpath('//a[@class= "amore"]/@href')
        print(is_page )
        if is_page:
            page += 1
            print('111111111111111111111111111')
            print(page)
        else:
            print("没有下一页")
            break









